#include "string.h"
#include <jni.h>
#include "UhfReader_API.h"
#include "ModuleControl.h"
#include "android/log.h"

static const char *TAG="ModuleControl";
#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO,  TAG, fmt, ##args)
#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, TAG, fmt, ##args)
#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args)

extern "C" {
/*�����Ƕ��⿪�ŵĽӿ� */
JNIEXPORT jint
JNICALL Java_com_raylinks_ModuleControl_UhfReaderConnect
		(JNIEnv *env, jobject thiz, jstring path, jint baudRate, jbyte flagCrc) {
	int result = -1;
	//int hCom[] = {-1};
	char temp[100];
	char *cPort = temp;

	jsize size = (*env)->GetStringLength(env, path);

	(*env)->GetStringUTFRegion(env, path, 0, size, cPort);

	result = UhfReaderConnect(cPort, baudRate, flagCrc);

	return result;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReaderDisconnect
		(JNIEnv *env, jobject thiz, jint fd, jbyte flagCrc) {
	int result = UhfReaderDisconnect(fd, flagCrc);
	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetPaStatus
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray status, jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, status, NULL);

	int result = UhfGetPaStatus(fd, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, status, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;

}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetPower
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bPower, jbyte flagCrc) {
	jbyte *tempPower = (*env)->GetByteArrayElements(env, bPower, NULL);

	int result = UhfGetPower(fd, tempPower, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bPower, tempPower, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfSetPower
		(JNIEnv *env, jobject thiz, jint fd, jbyte option, jbyte power, jbyte flagCrc) {
	int result = UhfSetPower(fd, option, power, flagCrc);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetFrequency
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bFreMode, jbyteArray bFreBase,
		 jbyteArray bBaseFre, jbyteArray bChannNum, jbyteArray bChannSpc, jbyteArray bFreHop,
		 jbyte flagCrc) {
	jbyte *tempFreMode = (*env)->GetByteArrayElements(env, bFreMode, NULL);
	jbyte *tempFreBase = (*env)->GetByteArrayElements(env, bFreBase, NULL);
	jbyte *tempBaseFre = (*env)->GetByteArrayElements(env, bBaseFre, NULL);
	jbyte *tempChannNum = (*env)->GetByteArrayElements(env, bChannNum, NULL);
	jbyte *tempChannSpc = (*env)->GetByteArrayElements(env, bChannSpc, NULL);
	jbyte *tempFreHop = (*env)->GetByteArrayElements(env, bFreHop, NULL);

	int result = UhfGetFrequency(fd, tempFreMode, tempFreBase, tempBaseFre, tempChannNum,
								 tempChannSpc, tempFreHop, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bFreMode, tempFreMode, 0);
	(*env)->ReleaseByteArrayElements(env, bFreBase, tempFreBase, 0);
	(*env)->ReleaseByteArrayElements(env, bBaseFre, tempBaseFre, 0);
	(*env)->ReleaseByteArrayElements(env, bChannNum, tempChannNum, 0);
	(*env)->ReleaseByteArrayElements(env, bChannSpc, tempChannSpc, 0);
	(*env)->ReleaseByteArrayElements(env, bFreHop, tempFreHop, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfSetFrequency
		(JNIEnv *env, jobject thiz, jint fd, jbyte freMode, jbyte freBase, jbyteArray bBaseFre,
		 jbyte channNum, jbyte channSpc, jbyte freHop, jbyte flagCrc) {
	jbyte *tempBaseFre = (*env)->GetByteArrayElements(env, bBaseFre, NULL);

	int result = UhfSetFrequency(fd, freMode, freBase, tempBaseFre, channNum, channSpc, freHop,
								 flagCrc);

	(*env)->ReleaseByteArrayElements(env, bBaseFre, tempBaseFre, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetReaderUID
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bUid, jbyte flagCrc) {
	jbyte *tempUid = (*env)->GetByteArrayElements(env, bUid, NULL);

	int result = UhfGetReaderUID(fd, tempUid, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bUid, tempUid, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfStartInventory
		(JNIEnv *env, jobject thiz, jint fd, jbyte flagAnti, jbyte initQ, jbyte flagCrc) {
	int result = UhfStartInventory(fd, flagAnti, initQ, flagCrc);
	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReadInventory
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bLenUii, jbyteArray bUii) {
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);

	int result = UhfReadInventory(fd, tempLenUii, tempUii);

	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfStopOperation
		(JNIEnv *env, jobject thiz, jint fd, jbyte flagCrc) {
	int result = UhfStopOperation(fd, flagCrc);
	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfInventorySingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bLenUii, jbyteArray bUii, jbyte flagCrc) {
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);

	int result = UhfInventorySingleTag(fd, tempLenUii, tempUii, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReadDataByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bUii, jbyteArray bReadData, jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempReadData = (*env)->GetByteArrayElements(env, bReadData, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfReadDataByEPC(fd, tempAccessPwd, bank, tempPtr, cnt, tempUii, tempReadData,
								  tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bReadData, tempReadData, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;

}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfWriteDataByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bUii, jbyteArray bWriteData, jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempWriteData = (*env)->GetByteArrayElements(env, bWriteData, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfWriteDataByEPC(fd, tempAccessPwd, bank, tempPtr, cnt, tempUii, tempWriteData,
								   tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteData, tempWriteData, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfEraseDataByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bUii, jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfEraseDataByEPC(fd, tempAccessPwd, bank, tempPtr, cnt, tempUii, tempErrorCode,
								   flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfLockMemByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyteArray bLockData,
		 jbyteArray bUii, jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempLockData = (*env)->GetByteArrayElements(env, bLockData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfLockMemByEPC(fd, tempAccessPwd, tempLockData, tempUii, tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bLockData, tempLockData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfKillTagByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bKillPwd, jbyteArray bUii,
		 jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempKillPwd = (*env)->GetByteArrayElements(env, bKillPwd, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfKillTagByEPC(fd, tempKillPwd, tempUii, tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bKillPwd, tempKillPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetVersion
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bSerial, jbyteArray bVersion,
		 jbyte flagCrc) {
	jbyte *tempSerial = (*env)->GetByteArrayElements(env, bSerial, NULL);
	jbyte *tempVersion = (*env)->GetByteArrayElements(env, bVersion, NULL);

	int result = UhfGetVersion(fd, tempSerial, tempVersion, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bSerial, tempSerial, 0);
	(*env)->ReleaseByteArrayElements(env, bVersion, tempVersion, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}

JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReadDataFromSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bReadData, jbyteArray bUii, jbyteArray bLenUii,
		 jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempReadData = (*env)->GetByteArrayElements(env, bReadData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfReadDataFromSingleTag(fd, tempAccessPwd, bank, tempPtr, cnt, tempReadData,
										  tempUii, tempLenUii, tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bReadData, tempReadData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfWriteDataToSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bWriteData, jbyteArray bUii, jbyteArray bLenUii,
		 jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempWriteData = (*env)->GetByteArrayElements(env, bWriteData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfWriteDataToSingleTag(fd, tempAccessPwd, bank, tempPtr, cnt, tempWriteData,
										 tempUii, tempLenUii, tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteData, tempWriteData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfBlockWriteDataByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bUii, jbyteArray bWriteData, jbyteArray bErrorCode,
		 jbyteArray bStatus, jbyteArray bWritedLen, jbyteArray RbUii, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempWriteData = (*env)->GetByteArrayElements(env, bWriteData, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempWritedLen = (*env)->GetByteArrayElements(env, bWritedLen, NULL);
	jbyte *tempRbUii = (*env)->GetByteArrayElements(env, RbUii, NULL);

	int result = UhfBlockWriteDataByEPC(fd, tempAccessPwd, bank, tempPtr, cnt, tempUii,
										tempWriteData, tempErrorCode, tempStatus, tempWritedLen,
										tempRbUii, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteData, tempWriteData, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);
	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bWritedLen, tempWritedLen, 0);
	(*env)->ReleaseByteArrayElements(env, RbUii, tempRbUii, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReadMaxDataByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyteArray bUii, jbyteArray Data_len, jbyteArray bReadData, jbyteArray bErrorCode,
		 jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempData_len = (*env)->GetByteArrayElements(env, Data_len, NULL);
	jbyte *tempReadData = (*env)->GetByteArrayElements(env, bReadData, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfReadMaxDataByEPC(fd, tempAccessPwd, bank, tempPtr, tempUii, tempData_len,
									 tempReadData, tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, Data_len, tempData_len, 0);
	(*env)->ReleaseByteArrayElements(env, bReadData, tempReadData, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReadMaxDataFromSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyteArray Data_len, jbyteArray bReadData, jbyteArray bUii, jbyteArray bLenUii,
		 jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempData_len = (*env)->GetByteArrayElements(env, Data_len, NULL);
	jbyte *tempReadData = (*env)->GetByteArrayElements(env, bReadData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfReadMaxDataFromSingleTag(fd, tempAccessPwd, bank, tempPtr, tempData_len,
											 tempReadData, tempUii, tempLenUii, tempErrorCode,
											 flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, Data_len, tempData_len, 0);
	(*env)->ReleaseByteArrayElements(env, bReadData, tempReadData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfEraseDataFromSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bUii, jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfEraseDataFromSingleTag(fd, tempAccessPwd, bank, tempPtr, cnt, tempUii,
										   tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfLockMemFromSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyteArray bLockData,
		 jbyteArray bUii, jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempLockData = (*env)->GetByteArrayElements(env, bLockData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfLockMemFromSingleTag(fd, tempAccessPwd, tempLockData, tempUii, tempErrorCode,
										 flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bLockData, tempLockData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfKillSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bKillPwd, jbyteArray bUii,
		 jbyteArray bErrorCode, jbyte flagCrc) {
	jbyte *tempKillPwd = (*env)->GetByteArrayElements(env, bKillPwd, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);

	int result = UhfKillSingleTag(fd, tempKillPwd, tempUii, tempErrorCode, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bKillPwd, tempKillPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfBlockWriteDataToSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyteArray bWriteData, jbyteArray bUii, jbyteArray bLenUii, jbyteArray bStatus,
		 jbyteArray bErrorCode, jbyteArray bWritedLen, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempWriteData = (*env)->GetByteArrayElements(env, bWriteData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);
	jbyte *tempWritedLen = (*env)->GetByteArrayElements(env, bWritedLen, NULL);

	int result = UhfBlockWriteDataToSingleTag(fd, tempAccessPwd, bank, tempPtr, cnt, tempWriteData,
											  tempUii, tempLenUii, tempStatus, tempErrorCode,
											  tempWritedLen, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteData, tempWriteData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);
	(*env)->ReleaseByteArrayElements(env, bWritedLen, tempWritedLen, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfStartReadDataFromMultiTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte bank, jbyteArray bPtr,
		 jbyte cnt, jbyte option, jbyteArray bPayLoad, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, bPtr, NULL);
	jbyte *tempPayLoad = (*env)->GetByteArrayElements(env, bPayLoad, NULL);

	int result = UhfStartReadDataFromMultiTag(fd, tempAccessPwd, bank, tempPtr, cnt, option,
											  tempPayLoad, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bPtr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, bPayLoad, tempPayLoad, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetDataFromMultiTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bStatus, jbyteArray bfData_len,
		 jbyteArray bfReadData, jbyteArray bsData_len, jbyteArray bsReadData, jbyteArray bUii,
		 jbyteArray bLenUii) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempfData_len = (*env)->GetByteArrayElements(env, bfData_len, NULL);
	jbyte *tempfReadData = (*env)->GetByteArrayElements(env, bfReadData, NULL);
	jbyte *tempsData_len = (*env)->GetByteArrayElements(env, bsData_len, NULL);
	jbyte *tempsReadData = (*env)->GetByteArrayElements(env, bsReadData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);

	int result = UhfGetDataFromMultiTag(fd, tempStatus, tempfData_len, tempfReadData, tempsData_len,
										tempsReadData, tempUii, tempLenUii);

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bfData_len, tempfData_len, 0);
	(*env)->ReleaseByteArrayElements(env, bfReadData, tempfReadData, 0);
	(*env)->ReleaseByteArrayElements(env, bsData_len, tempsData_len, 0);
	(*env)->ReleaseByteArrayElements(env, bsReadData, tempsReadData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfGetRegister
		(JNIEnv *env, jobject thiz, jint fd, jint RADD, jint RLEN, jbyteArray bStatus,
		 jbyteArray REG, jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempREG = (*env)->GetByteArrayElements(env, REG, NULL);

	int result = UhfGetRegister(fd, RADD, RLEN, tempStatus, tempREG, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, REG, tempREG, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfSetRegister
		(JNIEnv *env, jobject thiz, jint fd, jint RADD, jint RLEN, jbyteArray REG_DATA,
		 jbyteArray bStatus, jbyte flagCrc) {
	jbyte *tempREG_DATA = (*env)->GetByteArrayElements(env, REG_DATA, NULL);
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);

	int result = UhfSetRegister(fd, RADD, RLEN, tempREG_DATA, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, REG_DATA, tempREG_DATA, 0);
	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfResetRegister
		(JNIEnv *env, jobject thiz, jint fd, jbyte flagCrc) {
	int result = UhfResetRegister(fd, flagCrc);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfSaveRegister
		(JNIEnv *env, jobject thiz, jint fd, jbyte flagCrc) {
	int result = UhfSaveRegister(fd, flagCrc);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfEnterSleepMode
		(JNIEnv *env, jobject thiz, jint fd, jbyte flagCrc) {
	int result = UhfEnterSleepMode(fd, flagCrc);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jint
JNICALL Java_com_raylinks_ModuleControl_UhfUpdateInit
		(JNIEnv *env, jobject thiz, jstring path, jint baudRate, jbyteArray bStatus,
		 jbyteArray RN32, jbyte flagCrc) {
	int result = -1;
	int hCom[] = {-1};
	char temp[100];
	char *cPort = temp;

	jsize size = (*env)->GetStringLength(env, path);
	(*env)->GetStringUTFRegion(env, path, 0, size, cPort);

	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempRN32 = (*env)->GetByteArrayElements(env, RN32, NULL);

	if (UhfUpdateInit(hCom, cPort, baudRate, tempStatus, tempRN32, flagCrc) == 1) {
		result = hCom[0];
	}

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, RN32, tempRN32, 0);

	return result;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfUpdateSendRN32
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray RN32, jbyteArray bStatus, jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempRN32 = (*env)->GetByteArrayElements(env, RN32, NULL);

	int result = UhfUpdateSendRN32(fd, tempRN32, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, RN32, tempRN32, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfUpdateSendSize
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bStatus, jbyteArray bFileSize,
		 jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempFileSize = (*env)->GetByteArrayElements(env, bFileSize, NULL);

	int result = UhfUpdateSendSize(fd, tempStatus, tempFileSize, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bFileSize, tempFileSize, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfUpdateSendData
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bStatus, jbyte PACKNUM, jbyte LASTPACK,
		 jint Data_len, jbyteArray bTranData, jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempTranData = (*env)->GetByteArrayElements(env, bTranData, NULL);

	int result = UhfUpdateSendData(fd, tempStatus, PACKNUM, LASTPACK, Data_len, tempTranData,
								   flagCrc);

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bTranData, tempTranData, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfUpdateCommit
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bStatus, jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);

	int result = UhfUpdateCommit(fd, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfBlockWriteEPCToSingleTag
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte cnt,
		 jbyteArray bWriteData, jbyteArray bUii, jbyteArray bLenUii, jbyteArray bStatus,
		 jbyteArray bErrorCode, jbyteArray bWriteLen, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempWriteData = (*env)->GetByteArrayElements(env, bWriteData, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempLenUii = (*env)->GetByteArrayElements(env, bLenUii, NULL);
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);
	jbyte *tempWriteLen = (*env)->GetByteArrayElements(env, bWriteLen, NULL);

	int result = UhfBlockWriteEPCToSingleTag(fd, tempAccessPwd, cnt, tempWriteData, tempUii,
											 tempLenUii, tempStatus, tempErrorCode, tempWriteLen,
											 flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteData, tempWriteData, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bLenUii, tempLenUii, 0);
	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteLen, tempWriteLen, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}


JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfBlockWriteEPCByEPC
		(JNIEnv *env, jobject thiz, jint fd, jbyteArray bAccessPwd, jbyte cnt, jbyteArray bUii,
		 jbyteArray bWriteData, jbyteArray bErrorCode, jbyteArray bStatus, jbyteArray bWriteLen,
		 jbyteArray RuUii, jbyte flagCrc) {
	jbyte *tempAccessPwd = (*env)->GetByteArrayElements(env, bAccessPwd, NULL);
	jbyte *tempUii = (*env)->GetByteArrayElements(env, bUii, NULL);
	jbyte *tempWriteData = (*env)->GetByteArrayElements(env, bWriteData, NULL);
	jbyte *tempErrorCode = (*env)->GetByteArrayElements(env, bErrorCode, NULL);
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, bStatus, NULL);
	jbyte *tempWriteLen = (*env)->GetByteArrayElements(env, bWriteLen, NULL);
	jbyte *tempRuUii = (*env)->GetByteArrayElements(env, RuUii, NULL);

	int result = UhfBlockWriteEPCByEPC(fd, tempAccessPwd, cnt, tempUii, tempWriteData,
									   tempErrorCode, tempStatus, tempWriteLen, tempRuUii, flagCrc);

	(*env)->ReleaseByteArrayElements(env, bAccessPwd, tempAccessPwd, 0);
	(*env)->ReleaseByteArrayElements(env, bUii, tempUii, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteData, tempWriteData, 0);
	(*env)->ReleaseByteArrayElements(env, bErrorCode, tempErrorCode, 0);
	(*env)->ReleaseByteArrayElements(env, bStatus, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, bWriteLen, tempWriteLen, 0);
	(*env)->ReleaseByteArrayElements(env, RuUii, tempRuUii, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}

JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfAddFilter
		(JNIEnv *env, jclass thiz, jint fd, jbyte Sindex, jbyte Target, jbyte Action, jbyte bank,
		 jbyteArray Ptr, jbyteArray Mask, jbyte Truncate, jbyteArray STATUS, jbyte flagCrc) {
	SRECORD *pSRecord = malloc(sizeof(SRECORD));
	int i = 0;
	jbyte Slen = 0;
	jbyte Len = 0;
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, Ptr, NULL);
	jbyte *tempMask = (*env)->GetByteArrayElements(env, Mask, NULL);
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, STATUS, NULL);
	if ((tempPtr[0] & 0x80) == 0x00) {
		Slen = 8;
		pSRecord->Ptr[0] = tempPtr[0];
	} else {
		Slen = 9;
		pSRecord->Ptr[0] = tempPtr[0];
		pSRecord->Ptr[1] = tempPtr[1];
	}

	Len = (*env)->GetArrayLength(env, Mask);

	for (i = 0; i < Len; i++) {
		pSRecord->Mask[i] = tempMask[i];
	}
	Slen = Slen + Len;
	pSRecord->Sindex = Sindex;
	pSRecord->Slen = Slen;
	pSRecord->Target = Target;
	pSRecord->Action = Action;
	pSRecord->bank = bank;
	pSRecord->Len = (8 * Len);
	pSRecord->Truncate = Truncate;

	int result = UhfAddFilter(fd, pSRecord, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, Ptr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, Mask, tempMask, 0);
	(*env)->ReleaseByteArrayElements(env, STATUS, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}

JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfDeleteFilterByIndex
		(JNIEnv *env, jclass thiz, jint fd, jbyte SINDEX, jbyteArray STATUS, jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, STATUS, NULL);

	int result = UhfDeleteFilterByIndex(fd, SINDEX, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, STATUS, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}

JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfStartGetFilterByIndex
		(JNIEnv *env, jclass thiz, jint fd, jbyte SINDEX, jbyte SNUM, jbyteArray STATUS,
		 jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, STATUS, NULL);

	int result = UhfStartGetFilterByIndex(fd, SINDEX, SNUM, tempStatus, flagCrc);

	(*env)->ReleaseByteArrayElements(env, STATUS, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}

JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfReadFilterByIndex
		(JNIEnv *env, jclass thiz, jint fd, jbyteArray STATUS, jbyteArray Sindex, jbyteArray Slen,
		 jbyteArray Target, jbyteArray Action, jbyteArray bank, jbyteArray Ptr, jbyteArray Len,
		 jbyteArray Mask, jbyteArray Truncate) {
	int i = 0;
	int length = 0;
	SRECORD *pSRecord = malloc(sizeof(SRECORD));
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, STATUS, NULL);
	jbyte *tempSindex = (*env)->GetByteArrayElements(env, Sindex, NULL);
	jbyte *tempSlen = (*env)->GetByteArrayElements(env, Slen, NULL);
	jbyte *tempTarget = (*env)->GetByteArrayElements(env, Target, NULL);
	jbyte *tempAction = (*env)->GetByteArrayElements(env, Action, NULL);
	jbyte *tempbank = (*env)->GetByteArrayElements(env, bank, NULL);
	jbyte *tempPtr = (*env)->GetByteArrayElements(env, Ptr, NULL);
	jbyte *tempLen = (*env)->GetByteArrayElements(env, Len, NULL);
	jbyte *tempMask = (*env)->GetByteArrayElements(env, Mask, NULL);
	jbyte *tempTruncate = (*env)->GetByteArrayElements(env, Truncate, NULL);

	int result = UhfReadFilterByIndex(fd, tempStatus, pSRecord);

	*tempSindex = pSRecord->Sindex;
	*tempSlen = pSRecord->Slen;
	*tempAction = pSRecord->Action;
	*tempTarget = pSRecord->Target;
	*tempbank = pSRecord->bank;
	*tempLen = pSRecord->Len;
	length = pSRecord->Len / 8;
	*tempTruncate = pSRecord->Truncate;
	if (pSRecord->Ptr[0] & 0x80 == 0) {
		*tempPtr = pSRecord->Ptr[0];
	} else {
		*tempPtr = pSRecord->Ptr[0];
		*(tempPtr + 1) = pSRecord->Ptr[1];
	}

	for (i = 0; i < length; i++) {
		*(tempMask + i) = pSRecord->Mask[i];
	}

	(*env)->ReleaseByteArrayElements(env, STATUS, tempStatus, 0);
	(*env)->ReleaseByteArrayElements(env, Sindex, tempSindex, 0);
	(*env)->ReleaseByteArrayElements(env, Slen, tempSlen, 0);
	(*env)->ReleaseByteArrayElements(env, Action, tempAction, 0);
	(*env)->ReleaseByteArrayElements(env, Target, tempTarget, 0);
	(*env)->ReleaseByteArrayElements(env, bank, tempbank, 0);
	(*env)->ReleaseByteArrayElements(env, Ptr, tempPtr, 0);
	(*env)->ReleaseByteArrayElements(env, Len, tempLen, 0);
	(*env)->ReleaseByteArrayElements(env, Mask, tempMask, 0);
	(*env)->ReleaseByteArrayElements(env, Truncate, tempTruncate, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}

JNIEXPORT jboolean
JNICALL Java_com_raylinks_ModuleControl_UhfSelectFilterByIndex
		(JNIEnv *env, jclass thiz, jint fd, jbyte SINDEX, jbyte SNUM, jbyteArray STATUS,
		 jbyte flagCrc) {
	jbyte *tempStatus = (*env)->GetByteArrayElements(env, STATUS, NULL);
	int result = UhfSelectFilterByIndex(fd, SINDEX, SNUM, tempStatus, flagCrc);
	(*env)->ReleaseByteArrayElements(env, STATUS, tempStatus, 0);

	if (result == 1)
		return JNI_TRUE;
	else
		return JNI_FALSE;
}
}
  
#ifdef __cplusplus
}
#endif
